package com.four.homepage.Task;

import com.four.homepage.common.bean.ResponseData;
import com.four.homepage.common.controller.BaseController;
import com.four.homepage.todo.TodoEntity;
import com.four.homepage.todo.TodoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/task")
public class TaskController extends BaseController {
    @Autowired
    private TaskService taskService;

    //查
    @GetMapping("/list")
    public ResponseData<Object> listAllTasks() {
        return returnObject(taskService.selectAllTasks());
    }

    //删
    @DeleteMapping("/del/{id}")
    public ResponseData<Boolean> deleteTaskById(@PathVariable("id")Integer id){
        return returnBoolean(taskService.deleteTaskById(id));
    }

    //增
    @PostMapping("/add")
    public ResponseData<Boolean> addTask(@RequestBody TaskEntity taskEntity){
        return returnBoolean(taskService.insertTask(taskEntity));
    }
}
